package grame;
/**
 * Represents directions with X and Y values
 * @author moomoohk (moomoohk@ymail.com)
 */
public class Dir
{
	private int x, y;
	/**
	 * Creates a new {@link Dir} according to String
	 * @param dir "Up" for an "up" Dir, "down" for a "down" dir and so on
	 */
	public Dir(String dir)
	{
		this.x=0;
		this.y=0;
		if(dir.equalsIgnoreCase("up"))
			this.y=-1;
		if(dir.equalsIgnoreCase("down"))
			this.y=1;
		if(dir.equalsIgnoreCase("left"))
			this.x=-1;
		if(dir.equalsIgnoreCase("right"))
			this.x=1;
	}
	/**
	 * Creates a new {@link Dir} according to calculations
	 * @param a Start point
	 * @param b End point
	 */
	public Dir(Coordinates a, Coordinates b)
	{
		this.x=0;
		this.y=0;
		int xa=a.getX(), ya=a.getY();
		int xb=b.getX(), yb=b.getY();
		if((xa>xb)&&(ya==yb))
			this.x=-1;
		if((xa<xb)&&(ya==yb))
			this.x=1;
		if((xa==xb)&&(ya<yb))
			this.y=1;
		if((xa==xb)&&(ya>yb))
			this.y=-1;
		if((xa>xb)&&(ya<yb))
		{
			this.x=-1;
			this.y=1;
		}
		if((xa<xb)&&(ya>yb))
		{
			this.x=1;
			this.y=-1;
		}
		if((xa<xb)&&(ya<yb))
		{
			this.x=1;
			this.y=1;
		}
		if((xa>xb)&&(ya>yb))
		{
			this.x=-1;
			this.y=-1;
		}
	}
	public Dir(int x, int y)
	{
		this.x=x;
		this.y=y;
	}
	int getX()
	{
		return this.x;
	}
	int getY()
	{
		return this.y;
	}
	public String toString()
	{
		String st="";
		if(this.y==1)
			st+="Down ";
		if(this.y==-1)
			st+="Up ";
		if(this.x==1)
			st+="Right ";
		if(this.x==-1)
			st+="Left ";
		return st;
	}
}